﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;

namespace Test
{
    class TestHttpRequest
    {
        public static void Start()
        {
            //如果有特殊字符，应该使用转义
            String postData = "appkey=520520test&secretcode=f216e72ec72d777b3ce470d891c760fe&pageno=1&pagesize=20";
            Byte[] bs = Encoding.ASCII.GetBytes(postData);
            WebRequest req = WebRequest.Create("http://open.sharesdk.cn/api/share/List");
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = bs.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
            }
            WebResponse webres = req.GetResponse();
            Stream stream = webres.GetResponseStream();
            using (MemoryStream ms = new MemoryStream())
            {
                Byte[] buffer = new Byte[1024];
                Int32 read = stream.Read(buffer, 0, buffer.Length);
                while (read > 0)
                {
                    ms.Write(buffer, 0, read);
                    read = stream.Read(buffer, 0, buffer.Length);
                }
                Console.Write(Encoding.UTF8.GetString(buffer));
            }
        }
    }
}
